package cn.lijiajia3515.cairo.starter.autoconfigure.security;

import cn.lijiajia3515.cairo.security.web.authentication.CairoHttpMessageAccessDeniedHandler;
import cn.lijiajia3515.cairo.security.web.authentication.CairoHttpMessageAuthenticationEntryPoint;
import cn.lijiajia3515.cairo.security.web.authentication.CairoHttpMessageAuthenticationFailedHandler;
import cn.lijiajia3515.cairo.security.web.authentication.CairoHttpMessageAuthenticationSuccessHandler;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration(proxyBeanMethods = false)
public class CairoSecurityConfiguration {

	@Bean
	@ConditionalOnMissingBean
	public CairoHttpMessageAuthenticationEntryPoint cairoHttpMessageAuthenticationEntryPoint(HttpMessageConverters messageConverters) {
		return new CairoHttpMessageAuthenticationEntryPoint(messageConverters.getConverters());
	}

	@Bean
	@ConditionalOnMissingBean
	public CairoHttpMessageAuthenticationFailedHandler cairoAuthenticationFailedHandler(HttpMessageConverters messageConverters) {
		return new CairoHttpMessageAuthenticationFailedHandler(messageConverters.getConverters());
	}

	@Bean
	@ConditionalOnMissingBean
	public CairoHttpMessageAccessDeniedHandler cairoBearerTokenAccessDeniedHandler(HttpMessageConverters messageConverters) {
		return new CairoHttpMessageAccessDeniedHandler(messageConverters.getConverters());
	}

	@Bean
	@ConditionalOnMissingBean
	public CairoHttpMessageAuthenticationSuccessHandler successHandler(HttpMessageConverters messageConverters) {
		return new CairoHttpMessageAuthenticationSuccessHandler(messageConverters.getConverters());
	}

}
